package com.wwinsoft.framework.dao.security;

import java.util.List;

import org.springframework.stereotype.Component;

import com.wwinsoft.framework.entity.security.User;
import com.wwinsoft.modules.orm.Page;
import com.wwinsoft.modules.orm.PropertyFilter;
import com.wwinsoft.modules.orm.hibernate.HibernateDao;

@Component
public class UserDao extends HibernateDao<User, Long> {

    private static final String SELECT_UI_DEPT_ID = "select g.id from User u,MemberShip ms,Group g where u.userId=ms.key.userId and ms.key.groupId = g.deptId  and ms.type=0 and u.id=?";

    public Page<User> findPage(final Page<User> page, final List<PropertyFilter> filters) {
        this.getSession().enableFilter("defaultGroupFilter");
        return super.findPage(page, filters);
    }

    public List<User> findList(final List<PropertyFilter> filters) {
        this.getSession().enableFilter("defaultGroupFilter");
        return super.find(filters);
    }

    public User getUserByUserId(String userId){
        return findUniqueBy("userId",userId);
    }

    public User getUserByUserIdWtihFilter(String userId){
        this.getSession().enableFilter("defaultGroupFilter");
        return findUniqueBy("userId",userId);
    }

    public List<Long> getUIDeptId(Long id){
        return  find(SELECT_UI_DEPT_ID, id);
    }

}
